<template>
  <div class="vue-box sbot sbot-fluid">
    <!-- 参数栏 -->
    <div class="c-panel">
      <el-form :inline="true">
        <!-- 表单 -->
        <sa-item v-model="m.name" type="text" name="广告名" br />
        <sa-item v-model="m.code" type="text" name="识别码" br />
        <sa-item v-model="m.type" type="enum" jtype="4" :jv="dims.ADS_TYPE" name="类型" br />
        <sa-item name="广告位" br>
          <template>
            <el-select v-model="m.spaceId" placeholder="所属广告位" clearable>
              <el-option v-for="(item, index) in adsSpace" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </template>
        </sa-item>
        <sa-item v-model="m.url" type="text" name="广告URL" br />
        <sa-item v-model="m.img" type="img" name="商家LOGO" br />
        <sa-item v-model="m.thumbnail" type="img-list" name="广告图" br />
        <sa-item type="date-range" name="有效期" :start.sync="m.startDate" :end.sync="m.endDate" :clearable="true" />
        <sa-item v-model="m.auditStatus" type="enum" jtype="3" :jv="dims.AUDIT_STATUS" name="审核状态" br />
        <sa-item v-model="m.status" type="enum" jtype="3" :jv="dims.YES_OR_NO" name="启用状态" br />
        <sa-item v-model="m.note" type="text" name="描述" br />
        <sa-item v-model="m.sort" type="num" name="序号" br />
        <sa-item name="" br class="s-ok">
          <el-button type="primary" icon="el-icon-plus" @click="ok()">保存</el-button>
        </sa-item>
      </el-form>
    </div>
  </div>
</template>

<script>

export default {
  name: 'ads-add',
  props: { param: Object },
  data() {
    return {
      // 超级对象
      m: this.createModel(),
      dims: this.param.dims,
      adsSpace: this.param.adsSpace,
    }
  },
  created: function () {
  },
  watch: {
  },
  methods: {
    createModel() {
      return {}
    },
    // 变更
    ok: function () {
      // 表单校验
      let m = this.m;
      sa.checkNull(m.name, '请输入广告名');
      sa.checkNull(m.code, '请输入识别码');
      sa.checkNull(m.status, '请确认是否启用');

      // 添加
      sa.ajax('/ads/add', m, function (res) {
        if (res.code == 200) {
          sa.alert(res.msg, function () {
            this.m = this.createModel();
            sa.closeModel();
            sa.currView().f5();
          }.bind(this));
        }
      }.bind(this), { type: 'post' });
    },
  }
}
</script>

<style scoped></style>